<template>
    <!-- 接诊信息 -->
    <section v-if="loaded">
        <navBar :titleName="titleName"></navBar>
        <!--<loading v-if="isLoading"></loading>-->
        <header class="head-wrap">
            <h3 class="h3">{{formData.patientName}}</h3>
            <h5 class="h5">{{this.sexDatamap[""+formData.patientGender]}} {{formData.nation}} {{formData.eduLevel}}</h5>
            <button @click="showCompleteAccept">{{btnMsg}}</button>
        </header>

        <div v-show="showComplete">
            <div class="form-group">
                <formCell v-model="formData.height" title="身高" placeholder="请输入" tag="number" suffix="cm"
                          :readonly="readonly"/>
            </div>

            <div class="form-group">
                <formCell v-model="formData.weight" title="体重" placeholder="请输入" tag="number" suffix="kg"
                          :readonly="readonly"/>
            </div>
            <div class="form-group">
                <formCell v-model="formData.temperature" title="体温" placeholder="请选择" tag="number" suffix="℃"
                          :readonly="readonly"/>
            </div>
            <div class="form-group">
                <formCell v-model="formData.breath" title="呼吸" placeholder="请输入" tag="number" :readonly="readonly"/>
            </div>
            <div class="form-group">
                <formCell v-model="formData.max_bp" title="高血压" placeholder="请输入" tag="number" :readonly="readonly"/>
            </div>
            <div class="form-group">
                <formCell v-model="formData.min_bp" title="低血压" placeholder="请输入" tag="number" :readonly="readonly"/>
            </div>
            <div class="form-group">
                <formCell v-model="formData.pulse" title="脉搏" placeholder="请输入" tag="number" :readonly="readonly"/>
            </div>
            <div class="cutline"></div>
        </div>
        <div class="form-group">
            <formCell title="主诉" align="top">
                    <textarea v-model="formData.chiefComplaint" class="item-textarea" placeholder="患者病患描述" readonly
                              v-if="readonly"></textarea>
                <textarea v-model="formData.chiefComplaint" class="item-textarea" placeholder="患者病患描述"
                          v-else></textarea>
            </formCell>
        </div>

        <div class="cutline"></div>
        <div class="form-group">
            <!--<formCell v-model="formData.physicalCheck" title="体格检查" placeholder="患者病症" tag="input"
                      :readonly="readonly"></formCell>-->
            <formCell title="体格检查" align="top">
                    <textarea v-model="formData.physicalCheck" class="item-textarea" placeholder="体格检查" readonly
                              v-if="readonly"></textarea>
                <textarea v-model="formData.physicalCheck" class="item-textarea" placeholder="体格检查"
                          v-else></textarea>
            </formCell>
        </div>

        <div class="cutline"></div>
        <div class="form-group">
            <formCell title="既往史" align="top">
                <textarea v-model="formData.his_record" class="item-textarea" placeholder="请输入既往史" readonly
                          v-if="readonly"></textarea>
                <textarea v-model="formData.his_record" class="item-textarea" placeholder="请输入既往史" v-else></textarea>
            </formCell>
        </div>
        <div class="cutline"></div>
        <div class="form-group">
            <formCell title="过敏史" align="top" :readonly="readonly">
                <textarea v-model="formData.allergry" class="item-textarea" placeholder="请输入过敏史" readonly
                          v-if="readonly"></textarea>
                <textarea v-model="formData.allergry" class="item-textarea" placeholder="请输入过敏史" v-else></textarea>
            </formCell>
        </div>

        <div class="cutline"></div>
        <div class="form-group">
            <formCell v-model="formData.diagMain" title="主诊断" :placeholder="formData.diagMain" icon="true"
                      :notNull="true" :readonly="readonly" @myClickHandler="chooseDiag('diagMain')"></formCell>
        </div>
        <div class="form-group">
            <formCell v-model="formData.diagSecond" title="次诊断" :placeholder="formData.diagSecond" icon="true"
                      :readonly="readonly" @myClickHandler="chooseDiag('diagSecond')"></formCell>
        </div>
        <div class="cutline"></div>

        <nav class="nav-list">
            <!--<div class="item" :class="{active:navActive==1}" @click="navActive=1">主诉与诊断</div>-->
            <div class="item" :class="{active:navActive==1}" @click="navActive=1">处置与建议</div>
            <div class="item" :class="{active:navActive==2}" @click="navActive=2">处方开药</div>
            <div class="item" :class="{active:navActive==3}" @click="navActive=3">其他收费</div>
        </nav>

        <!--<div class="nav-content" comment="诊断" v-if="navActive==1">
            <h3>【接诊说明】</h3>

            <div class="form-group">
                <formCell title="现病史" align="top">
                    <textarea v-model="formData.hpi" class="item-textarea" placeholder="患者现病史描述" readonly
                              v-if="readonly"></textarea>
                    <textarea v-model="formData.hpi" class="item-textarea" placeholder="患者现病史描述" v-else></textarea>
                </formCell>
            </div>
        </div>-->

        <div class="nav-content" comment="处置建议" v-if="navActive==1">
            <div class="cost-ul">
                <h3>【治疗说明】</h3>
                <div class="form-group">
                    <formCell title="处理" align="top">
                    <textarea v-model="formData.comments" class="item-textarea" placeholder="输入治疗建议" readonly
                              v-if="readonly"></textarea>
                        <textarea v-model="formData.comments" class="item-textarea" placeholder="输入治疗建议"
                                  v-else></textarea>
                    </formCell>
                </div>
                <div class="form-group">
                    <formCell title="用药" align="top">
                    <textarea v-model="formData.drug" class="item-textarea" placeholder="患者现病史描述" readonly
                              v-if="readonly"></textarea>
                        <textarea v-model="formData.drug" class="item-textarea" placeholder="患者现病史描述" v-else></textarea>
                    </formCell>
                </div>
                <div class="form-group">
                    <formCell title="打针" align="top">
                    <textarea v-model="formData.injection" class="item-textarea" placeholder="输入打针建议" readonly
                              v-if="readonly"></textarea>
                        <textarea v-model="formData.injection" class="item-textarea" placeholder="输入打针建议"
                                  v-else></textarea>
                    </formCell>
                </div>
                <div class="form-group">
                    <formCell title="随访" align="top">
                    <textarea v-model="formData.recommendations" class="item-textarea" placeholder="输入随访建议" readonly
                              v-if="readonly"></textarea>
                        <textarea v-model="formData.recommendations" class="item-textarea" placeholder="输入随访建议"
                                  v-else></textarea>
                    </formCell>
                </div>
            </div>
        </div>

        <div class="nav-content" comment="处方开药" v-if="navActive==2">
            <template>
                <div v-for="(recipe,index) in medicineList" :key="index">

                    <ul class="ul-list">
                        <h3 v-if="recipe.recipeType == 1">【成药处方】</h3>
                        <h3 v-else>【中药处方】
                            <span style="float: right">
                                <nut-stepper
                                        :value.sync="recipe.recipeNum"
                                ></nut-stepper>
                            </span>
                        </h3>
                        <li class="li-item" v-for="(item, seq) in recipe.skus" :key="seq">
                            <div class="thumb">
                                <img :src="item.productImageurl" alt="">
                            </div>
                            <div class="md-cell" style="text-align: right;">
                                <p class="title">{{item.productName}}</p>
                                <p class="desc">{{item.packingProduct}}</p>
                                <p class="desc">总剂量{{item.num * item.dose}}</p>
                                <p class="price" style="display: none">￥{{ new Number(item.productPrice /
                                    100).toFixed(2)
                                    }}元</p>
                                <p class="cell-3" style="float: right;">
                                    <nut-stepper :value.sync="item.num"></nut-stepper>
                                </p>
                            </div>

                            <div class="md-cell">
                                <p class="title">给药途径<span style="color: red">*</span>：
                                    <!--<input v-model="item.administration" placeholder="请输入给药途径"/>-->
                                    <multiselect class="multiselect" v-model="item.administration"
                                                 :options="administration" placeholder="请输入给药途径"
                                                 @select="chooseSomething(item.administration,index,seq,'administration')"></multiselect>
                                    <!--<multiselect class="multiselect" v-model="item.administration" :options="administration" placeholder="请输入给药途径" v-show="true"
                                                 :reset-after="true" :custom-label="nameWithLang" :label="name" :trackBy="name" :value="name"
                                                 @select="chooseSomething(item.administration,index,seq)"></multiselect>-->
                                </p>
                                <p class="title">给药频率<span style="color: red">*</span>：
                                    <!--<input v-model="item.frequency" placeholder="请输入给药频率"/>-->
                                    <multiselect class="multiselect" v-model="item.frequency"
                                                 :options="frequency" placeholder="请输入给药频率"
                                                 @select="chooseSomething(item.frequency,index,seq,'frequency')"></multiselect>
                                </p>

                                <p class="title">单次剂量<span style="color: red">*</span>：
                                    <input v-model="item.dose" type="number" placeholder="请输入单次剂量"/>
                                </p>

                                <p class="title">给药次数<span style="color: red">*</span>：
                                    <input v-model="item.times" type="number" placeholder="请输入给药次数"/>
                                </p>
                            </div>
                        </li>
                        <div style="text-align:right;" v-if="!readonly">
                            <button class="btn btn-main "
                                    @click="addDrugs(recipe,index)">
                                添加药品
                            </button>
                        </div>
                    </ul>
                    <div class="cutline"></div>
                </div>
            </template>
            <div class="cutline"></div>
            <!-- <div class="btn-normal" @click="$router.push({name:'medicineList',params:{isadd:true,kind:1,patientId:formData.patientId,recordId:formData.recordId,doctorId:formData.doctorId}})">+新增处方</div> -->
            <div class="btn-normal" @click="onAdd(1)" v-if="!readonly">+新增成药处方</div>
            <!--<div class="btn-normal" @click="onAdd(2)">+新增中药处方</div>-->
        </div>

        <div class="nav-content" comment="其他收费" v-if="navActive==3">
            <ul class="cost-ul">
                <h3>【收费】</h3>
                <li v-for="(item, index) in costdataList" :key="index" @click="modCost(item,index)">
                    <p>{{item.name}}<span class="txt-gray">&nbsp;&nbsp; {{ new Number(item.price / 100 ).toFixed(2) }}元 &nbsp;&nbsp;&nbsp; 折扣：{{item.discount}}</span>
                    </p>
                    <p v-if="item.message" class="txt-gray">费用说明：{{item.message}}</p>
                    <p>
                        <span class="txt-gray nav-left">{{item.message}}</span>
                        <span class="txt-red price nav-right">￥{{ new Number(item.discountPrice / 100).toFixed(2) }}元</span>
                    </p>
                </li>
            </ul>
            <div class="btn-normal" @click="addCost()" v-if="!readonly">+新增收费</div>
        </div>

        <div class="cutline"></div>

        <div class="btn-group" v-if="!readonly">
            <button class="btn btn-main" @click="onSubmit(0)">接诊完成</button>
        </div>

        <div class="btn-group" v-if="!readonly">
            <button class="btn btn-gray" @click="onSubmit(1)">暂存病历</button>
        </div>
        <div class="cutline"></div>

        <nut-dialog :visible="dialogShow" @close="dialogShow=false" :noFooter="hideFooter" title="请让病人扫码支付">
            <logoQrcode :content="link" :width="width"/>
        </nut-dialog>


    </section>
</template>
<script>
    /* eslint-disable no-undef,no-console,no-unused-vars */

    import formCell from "@/components/common/formCell.vue";
    import loading from "@/components/common/loading.vue";
    import navBar from '@/components/common/navBar.vue'

    import logoQrcode from '@/components/common/my-code.vue'
    import Multiselect from 'vue-multiselect/src/Multiselect.vue'


    // import {pushHistory} from '../router/unit.js' // 引入工具类

    const components = {formCell, loading, logoQrcode, navBar, Multiselect};

    export default {
        components,
        filters: {
            getData(val) {
            }
        },
        data() {
            return {
                width: 130,
                titleName: '接诊',

                adviceId:-1,

                val: 1,
                loaded: false,
                showComplete: false,
                btnMsg: "完整版",

                dialogShow: false,
                hideFooter: true,
                link: "http://api.51self-service.cn/wx/authorize?returnUrl=http%3A%2F%2Fp.51self-service.cn", // 带图片二维码2

                isLoading: false,
                loading: null,
                readonly: false,
                keep: false,
                sexDatamap: {"1": "男", "2": "女", "0": "未知"},
                formData: {
                    "patientGender": 1, //性别
                    "patientName": "",  //病人姓名
                    "nation": "",       // 民族
                    "eduLevel": "",    //学历
                    "allergry": "",
                    "breath": "",
                    "hpi": "", //现病史
                    "chiefComplaint": "", //主诉
                    "physicalCheck": "",
                    "comments": "",
                    "diagMain": "请选择",  //主诊
                    "diagSecond": "请选择",  //次诊
                    "doctorId": "",  //医生id
                    "drug": "",
                    "freeInfoList": "[]",
                    "height": "",
                    "his_record": "",
                    "injection": "",
                    "max_bp": "",
                    "min_bp": "",
                    "orderNo": "",
                    "patientId": "",//病人id
                    "pulse": "",
                    "recipelSkuList": "[]",
                    "recordId": 1, //病历id
                    "temperature": "",
                    "weight": "",
                    "workspaceId": 1,
                    "recommendations": "",  //随访
                },
                medicineList: [],
                costdataList: [],
                navActive: 1, //
                isorder: false, //是否下单成功
                chufangList: localStorage.getItem("medicineData") ? JSON.parse(localStorage.getItem("medicineData")) : [], //处方数组队列

                // administration: [{"code":150,"name":"口服","key":"KF"},{"code":140,"name":"静脉输液","key":"JMSY"},{"code":18,"name":"小壶入","key":"XHR"},{"code":29,"name":"吸入","key":"XR"},{"code":143,"name":"静脉滴注ivd","key":"JMDZIVD"},{"code":144,"name":"肌肉注射","key":"JRZS"},{"code":145,"name":"皮下注射","key":"PXZS"},{"code":146,"name":"皮试","key":"PS"},{"code":147,"name":"皮内注射","key":"PNZS"},{"code":148,"name":"氧气雾化","key":"YQWH"},{"code":149,"name":"超声雾化","key":"CSWH"},{"code":200,"name":"饭前服","key":"FQF"},{"code":201,"name":"饭后服","key":"FHF"},{"code":202,"name":"与饭同服","key":"YFTF"},{"code":203,"name":"局麻用","key":"JMY"},{"code":204,"name":"封闭用","key":"FBY"},{"code":205,"name":"造影用","key":"ZYY"},{"code":206,"name":"冲洗用","key":"CXY"}]


                administration: ["001 口服 KF", "002 静脉输液 JMSY", "003 小壶入 XHR", "004 吸入 XR", "005 静脉滴注ivd JMDZIVD",
                    "006 肌肉注射 JRZS", "007 皮下注射 PXZS", "008 皮试 PS", "009 皮内注射 PNZS", "010 氧气雾化 YQWH",
                    "011 超声雾化 CSWH", "012 饭前服 FQF", "013 饭后服 FHF", "014 与饭同服 YFTF", "015 局麻用 JMY",
                    "016 封闭用 FBY", "017 造影用 ZYY", "018 冲洗用 CXY"],

                frequency: ["102 一天1次，餐后", "101 一天1次，餐前", "100 一天1次", "120 午餐后",
                    "110 中餐前", "130  中午1次", "140 晚餐后", "150 晚餐前", "160 晚上1次",
                    "240 睡前1次", "202 一天2次，餐后", "201 一天2次，餐前", "200 一天2次",
                    "302 一天3次，餐后", "301 一天3次，餐前", "300 一天3次", "402 一天4次，餐后加睡前",
                    "401 一天4次，餐前加睡前", "400 一天4次", "221 两天一次"],
            }
        },
        created() {
            console.log(this);

            let _that = this;
            this.$store.state.accept = _that;
            setTimeout(function () {
                _that.initWechat();
            }, 50);

            if (!this.$route.params.adviceId) {
                this.$router.push({
                    name: 'home'
                });
                return false;
            }
            this.adviceId = this.$route.params.adviceId;
            this.getInfo();
        },
        beforeRouteEnter(to, from, next) {
            document.title = "接诊";
            document.body.style.backgroundColor = "#e8e8e8";
            next();
        },
        beforeRouteLeave(to, from, next) {
            console.log("-------beforeRouteLeave-------");
            document.title = "接诊";
            document.body.style.backgroundColor = "#e8e8e8";
            /*if (!this.$store.state.keepAccept) {
                console.log("-------$destroy-------");
                this.$destroy();
                console.log("-------$destroy-------");
            }*/
            next();
            console.log("-------beforeRouteLeave-------");
        },
        activated(){
            console.log("--------activated-------");
            if(this.$route.params.adviceId && this.adviceId !== this.$route.params.adviceId){
                this.adviceId = this.$route.params.adviceId;
                console.log("--------activated getInfo-------");
                this.getInfo();
            }
            console.log("--------activated-------");
        },
        deactivated(){
            if (!this.$store.state.keepAccept) {
                console.log("-------deactivated destroy-------");
                // this.$destroy();
                console.log("-------deactivated destroy-------");
            }
            console.log("--------deactivated-------");
        },
        computed: {
            //收费项目
            free() {
                return this.$store.state.freeInfoList
            },
            //成药列表
            medicineList2() {
                return this.$store.state.medicineList
            },
            //中药列表
            medicineList1() {
                return []
            },
            diagMain() {
                return this.$store.state.diagMain;
            },
            diagSecond() {
                return this.$store.state.diagSecond;
            }
        },
        watch: {
            //收费项目
            free(curVal, oldVal) {
                //这里的curVal就是需要监听的值
                // this.$store.state.keepAccept = false;
                this.costdataList = this.$store.state.freeInfoList;
            },
            medicineList(curVal, oldVal) {
                // this.$store.state.keepAccept = false;
                this.medicineList = this.$store.state.medicineList;

                /*for(let recipe in this.medicineList){
                    for(let item in recipe.skus){
                        if (item.administration.name) {
                            item.administration = item.administration.name;
                        }
                    }
                }*/

            },
            diagMain(curVal, oldVal) {
                // this.$store.state.keepAccept = false;
                return this.formData.diagMain = this.$store.state.diagMain;
            },
            diagSecond(curVal, oldVal) {
                // this.$store.state.keepAccept = false;
                return this.formData.diagSecond = this.$store.state.diagSecond;
            }
        },
        methods: {
            chooseSomething(val, index, seq, key) {
                console.log("--------chooseSomething--------");

                let _that = this;
                console.log(_that);

                if (key == 1) {
                    key = "administration";
                }

                setTimeout(function () {
                    let d = _that.$data.medicineList[index].skus[seq][key];
                    if (/\s/.test(d)) {
                        _that.$data.medicineList[index].skus[seq][key] = d.split(" ")[1];
                    }
                }, 50);

                console.log(val);
                console.log(index);
                console.log(seq);
                /*val = JSON.parse(val);
                if (val && val.name) {
                    this.$data.medicineList[index].skus[seq].administration = val.name;
                }*/
                // debugger;
                console.log("--------chooseSomething--------");
            },
            nameWithLang({name, code, key}) {
                return `${code}  ${name}  ${key}`
                // return `${name}`
            },
            showCompleteAccept: function () {
                this.showComplete = !this.showComplete;
                this.btnMsg = this.btnMsg === "完整版" ? "简易版" : "完整版";
            },
            formatNum: function (d) {
                if (d != null && d !== 0) {
                    return d;
                } else {
                    return "";
                }
            },
            initWechat: function () {
                let _that = this;
                this.API.get(this.ApiUrl.GET_WECHAT, {
                    params: {
                        openid: this.$store.state.openid,
                        url: window.location.href.split("#")[0]
                    }
                }).then(({data}) => {
                    console.log("wxjssdk------", data);
                    wx.config({
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                        appId: data.data.appId, // 必填，公众号的唯一标识
                        timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                        nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                        signature: data.data.signature,// 必填，签名
                        jsApiList: [
                            "updateAppMessageShareData",
                            "onMenuShareAppMessage",
                            "onMenuShareTimeline",
                            "onMenuShareQQ"
                        ] // 必填，需要使用的JS接口列表
                    });
                    wx.ready(function () {   //需在用户可能点击分享按钮前就先调用

                    });
                    wx.error(function (res) {
                        // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，
                        // 也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
                        /*vm.$toast.text("微信初始化失败:" + JSON.stringify(res));
                        vm.initWechat();*/
                    });
                }).catch(err => {
                    console.log(err);
                    //请求异常，重试
                    // vm.initWechat();
                    _that.initWechat();
                });
            },

            chooseDiag(kind) {
                if (this.readonly) {
                    return false;
                }
                console.log("----chooseDiag----");
                console.log(kind);
                this.$store.state.keepAccept = true;
                this.$router.push({name: "searchDiag", params: {item: kind}})
                console.log("----chooseDiag----");
            },
            addDrugs(recipe, index) {
                if (this.readonly) {
                    return false;
                }
                this.$store.state.keepAccept = true;
                this.$router.push({
                    name: 'medicineList', params: {item: this.medicineList, index: index}
                });
            },
            //修改收费项目
            modCost(item, index) {
                if (this.readonly) {
                    return false;
                }

                if (item.name === "运费") {
                    return false;
                }
                this.$store.state.keepAccept = true;
                this.$router.push({
                    name: 'addCost', params: {item: item, index: index}
                });
            },
            //处方数据
            //[{"recipeId":"1","recipeType":"1",
            // "skus":[{"num":1,"productCode":"8","productName":"阿莫西林胶囊","skuId":"121","productPrice":"8000"}]}]
            // 新增处方
            onAdd(kind) {
                if (this.readonly) {
                    return false;
                }
                this.API.POST(this.ApiUrl.POST_ADD_RECIPEL, {
                    "doctorId": this.formData.doctorId,  //医生id
                    "kind": kind,      //成药处方 1成药 2中药处方，默认:1 ,
                    "patientId": this.formData.patientId, //病人id
                    "recordId": this.formData.recordId  //病历id(点击接诊时会返回病历id字段)
                }).then(({data}) => {
                    if (data.code === 1200) {
                        this.$toast.text("添加处方信息成功");
                        let item = {
                            "recipeId": data.data.recipelId,
                            "recipeType": kind,
                            "recipeNum": 1,
                            "skus": []
                        };
                        this.medicineList.push(item);
                    }
                }).catch(err => {
                    this.$toast.text("添加处方信息失败，请重试");
                });

            },
            addCost() {
                if (this.readonly) {
                    return false;
                }
                this.$store.state.keepAccept = true;
                this.$router.push({name: 'addCost'});
            },
            onSubmit(isPause) {
                this.$store.state.keepAccept = false;
                if (this.readonly) {
                    return false;
                }
                let fd = this.formData;
                console.log("提交数据---->", this.formData);
                let loading;

                if (isPause === 0) {
                    //正式提交
                    if (!this.formData.diagMain || this.formData.diagMain == "请选择") {
                        this.$toast.text("请选择主诊断");
                        return false;
                    }

                    let flag = false;
                    let msg = "";

                    for (let r = 0; r < this.medicineList.length; r++) {
                        let skus = this.medicineList[r].skus;
                        for (let s = 0; s < skus.length; s++) {
                            let item = skus[s];
                            if (item.administration === "" || item.administration.length === 0) {
                                flag = true;
                                msg = item.productName + " 给药途径";
                                break;
                            }
                            if (item.frequency === "" || item.frequency.length === 0) {
                                flag = true;
                                msg = item.productName + " 给药频率";
                                break;
                            }
                            if (item.dose === "" || item.dose.length === 0) {
                                flag = true;
                                msg = item.dose + " 单次剂量";
                                break;
                            }
                            if (item.times === "" || item.times.length === 0) {
                                flag = true;
                                msg = item.times + " 给药时间";
                                break;
                            }
                        }
                        if (flag) {
                            break;
                        }
                    }

                    if (flag) {
                        this.$toast.text("请选择" + msg);
                        return false;
                    }
                }

                if (!fd.height) {
                    this.formData.height = 0;
                }
                if (!fd.weight) {
                    this.formData.weight = 0;
                }
                if (!fd.breath) {
                    this.formData.breath = 0;
                }
                if (!fd.max_bp) {
                    this.formData.max_bp = 0;
                }
                if (!fd.min_bp) {
                    this.formData.min_bp = 0;
                }
                if (!fd.pulse) {
                    this.formData.pulse = 0;
                }
                if (!fd.temperature) {
                    this.formData.temperature = 0;
                }

                this.formData.recipelSkuList = this.medicineList;//JSON.stringify(recipelSkuList2);
                this.formData.freeInfoList = this.costdataList;//JSON.stringify(this.costdataList);
                //Loading类型，默认不会自动消失，带透明遮罩
                loading = this.$toast.loading();

                this.API.POST("/drs/preOrderByDr", {
                    "allergry": this.formData.allergry,
                    "breath": this.formData.breath,
                    "hpi": this.formData.hpi,
                    "chiefComplaint": this.formData.chiefComplaint,
                    "physicalCheck": this.formData.physicalCheck,
                    "comments": this.formData.comments,
                    "diagMain": this.formData.diagMain,
                    "diagSecond": this.formData.diagSecond,
                    "doctorId": this.formData.doctorId,
                    "drug": this.formData.drug,
                    "freeInfoList": this.formData.freeInfoList,
                    "height": this.formData.height,
                    "his_record": this.formData.his_record,
                    "injection": this.formData.injection,
                    "max_bp": this.formData.max_bp,
                    "min_bp": this.formData.min_bp,
                    "orderNo": this.formData.orderNo,
                    "patientId": this.formData.patientId,
                    "pulse": this.formData.pulse,
                    "recipelSkuList": this.formData.recipelSkuList,
                    "recordId": this.formData.recordId,
                    "temperature": this.formData.temperature,
                    "weight": this.formData.weight,
                    "workspaceId": this.formData.workspaceId,
                    "isPause": isPause
                })
                    .then(({data}) => {
                        this.isLoading = false;
                        //手动关闭上面的Loading
                        loading.hide();
                        if (+data.code === 1200) {
                            if (data.data.batchNo === "0000") {
                                this.$toast.text("暂存病历成功");
                                return false;
                            }
                            // vm.$toast.text("接诊完成，请点击右上角的分享给用户按钮，推送订单给病人");

                            this.link = "http://api.51self-service.cn/wx/authorize?returnUrl=http%3A%2F%2Fp.51self-service.cn%3ForderNo%3D"
                                + data.data.orderNo;

                            this.dialogShow = true;

                            let _that = this;
                            wx && wx.updateAppMessageShareData({
                                title: '测试', // 分享标题
                                desc: '测试', // 分享描述
                                link: "http://api.51self-service.cn/wx/authorize?returnUrl=http%3A%2F%2Fp.51self-service.cn%3ForderNo%3D" + data.data.orderNo,
                                // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                                imgUrl: '', // 分享图标
                                success: function () {
                                    _that.readonly = true;
                                    // alert("分享成功");
                                    // 设置成功
                                }
                            });

                        } else {
                            this.$toast.text(data.msg || "提交失败");
                        }
                    })
                //手动关闭上面的Loading
                loading.hide();
            },
            getInfo(){
                // 获取病人基本信息
                this.API(this.ApiUrl.GET_VISIT_ORDER, {
                    params: {
                        id: this.adviceId
                        // id: 40
                    }
                }).then(({data}) => {
                    this.loaded = true;

                    if (data.data) {
                        this.formData = Object.assign(this.formData, data.data.patient, data.data.recordInfo);
                        this.readonly = (data.data.recordInfo.isDelete === 0);
                        this.formData.max_bp = data.data.recordInfo.maxBp;
                        this.formData.min_bp = data.data.recordInfo.minBp;
                        this.formData.his_record = data.data.recordInfo.hisRecord;

                        if (data.data.diagnosis) {
                            this.formData.diagMain = data.data.diagnosis.diagMain;
                            this.formData.diagSecond = data.data.diagnosis.diagSecond;
                            this.formData.chiefComplaint = data.data.diagnosis.chiefComplaint;
                            this.formData.hpi = data.data.diagnosis.hpi;
                            this.formData.physicalCheck = data.data.diagnosis.physicalCheck;
                            this.formData.comments = data.data.diagnosis.comments;
                            this.formData.drug = data.data.diagnosis.drug;
                            this.formData.injection = data.data.diagnosis.injection;
                        }


                        this.costdataList = [
                            {
                                "discount": "全价",
                                "message": "诊金",
                                "name": "诊金",
                                "price": data.data.diagnosisFee,
                                "discountPrice": data.data.diagnosisFee
                            },
                            {
                                "discount": "全价",
                                "message": "运费",
                                "name": "运费",
                                "price": data.data.freight,
                                "discountPrice": data.data.freight
                            }
                        ];
                        this.$store.state.freeInfoList = this.costdataList;
                        this.medicineList = data.data.products ? JSON.parse(data.data.products) : [];
                        this.$store.state.medicineList = this.medicineList;

                        let fd = this.formData;
                        if (fd.height == 0) {
                            this.formData.height = "";
                        }
                        if (fd.weight == 0) {
                            this.formData.weight = "";
                        }
                        if (fd.breath == 0) {
                            this.formData.breath = "";
                        }
                        if (fd.max_bp == 0) {
                            this.formData.max_bp = "";
                        }
                        if (fd.min_bp == 0) {
                            this.formData.min_bp = "";
                        }
                        if (fd.pulse == 0) {
                            this.formData.pulse = "";
                        }

                        if (fd.temperature == 0) {
                            this.formData.temperature = "";
                        }

                    } else {
                        this.$toast.text(data.msg || "请求出错");
                    }
                })
            },
        },
    }
</script>


<style>
    .head-wrap {
        text-align: center;
        background-color: #fff;
        padding: 20px 0;
        margin-bottom: 10px;
        margin-top: 36px;
    }

    .head-wrap h3.h3 {
        font-size: 1.2em;
        font-weight: 400;
        color: #2D90DE;
        margin: 0;
    }

    .head-wrap h5.h5 {
        margin: 0;
        margin-top: 10px;
        font-weight: normal;
        font-size: 0.9em;
        color: #7E8A96;
    }

    .head-wrap button {
        float: right;
        margin-top: -40px;
        border: 0;
        background-color: #fff;
        padding-right: 10px;
    }

    .cutline {
        height: 10px;
    }

    .form-group {
        background-color: #fff;
        padding: 0px 10px;
    }

    .form-group .form-item {
        font-size: 0.9em;
        padding: 14px 0;
        border-bottom: 1px solid #e8e8e8;
    }

    .form-group .item-textarea {
        height: 50px;
    }

    .cost-ul {
        margin: 0;
        background-color: #fff;
        padding: 0 12px;
        text-align: left;
    }

    .cost-ul li {
        margin: 0;
        padding: 12px 0;
        border-top: solid 1px #efefef;
        list-style: none;
    }

    .cost-ul li .price {
        font-size: 1.4em;
    }

    .cost-ul li p {
        margin: 12px 0;
        padding: 0;
    }

    .txt-red {
        color: #D73A2C;
    }

    .txt-gray {
        color: #999;
    }

    .btn-main {
        border: none;
        background: #4aabf5;
        color: #fff;
        padding: 5px 10px;
        font-size: 0.9em;
        border-radius: 5px;
        margin: 5px 0;
    }

    .btn-normal {
        background-color: #fff;
        height: 40px;
        width: 100%;
        font-size: 0.9em;
        color: #828E99;
        line-height: 40px;
        text-align: center;
        border-top: solid 1px #efefef;
    }

    .nav-list {
        background-color: #ededed;
        display: flex;
        text-align: center;
        margin-top: 6px;
    }

    .nav-list .item {
        width: 33.3%;
        background-color: #fff;
        color: #7E8A96;
        font-size: 0.9em;
        font-weight: 400;
        padding: 12px 0;
        border-bottom: solid 3px #ededed;
    }

    .nav-list .item.active {
        color: #0091E1;
        border-bottom: solid 3px #2D90DE;
    }

    .nav-content h3 {
        margin: 0;
        border-bottom: 1px solid #ededed;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .btn-group {
        padding: 6px 12px;
    }

    .btn-group .btn {
        border: none;
        background-color: transparent;
        display: block;
        height: 45px;
        width: 100%;
        border-radius: 2px;
        font-size: 0.9em;
    }

    .btn-group .btn.btn-main {
        background-color: #2D90DE;
        color: #fff;
    }

    .btn-group .btn.btn-gray {
        background-color: #DADADA;
        color: #7E8A96;
        border: solid 1px #7E8A96;
    }

    .ul-list {
        margin: 0;
        padding: 0 12px;
        background-color: #fff;
    }

    .ul-list h3 {
        text-align: left;
    }

    .ul-list .li-item {
        background-color: #fff;
        font-size: 0.9em;
        display: flex;
        /*display: -webkit-box;*/
        padding: 16px 0;
        border-bottom: 1px solid #ededed;
        /*换行*/
        flex-wrap: wrap;
    }

    .ul-list .li-item .thumb {
        min-width: 100px;
        height: 80px;
        overflow: hidden;
        border: solid 1px #efefef;
    }

    .ul-list .li-item .thumb img {
        width: 100%;
    }

    .ul-list .li-item .md-cell {
        padding: 0 10px;
        flex-grow: 1;
        text-align: left;
    }

    .ul-list .li-item .title {
        font-size: 0.9em;
        color: #1D2030;
        display: flex;
    }

    .ul-list .li-item .title input {
        float: right;
        /*border-radius: 9px;*/
        width: 70%;
        border: 0;
        color: #1D2030;
        text-align: right;
    }

    .ul-list .li-item .desc {
        color: #7E8A96;
        font-size: 0.9em;
    }

    .ul-list .li-item .thumb .cell-3 {
        display: flex;
        align-items: center;
        color: #666;
        white-space: nowrap;
    }

    .ul-list .li-item .cell-3 {
        display: flex;
        align-items: center;
        color: #666;
        white-space: nowrap;
    }

    .ul-list .li-item p {
        margin: 8px 0;
        padding: 0;
    }

    .ul-list .li-item .price {
        color: #D73A2C;
        font-size: 1.4em;
    }

    /* 旋转效果 */
    .demo-spin-icon-load {
        animation: ani-demo-spin 1s linear infinite;
    }

    @keyframes ani-demo-spin {
        from {
            transform: rotate(0deg);
        }
        50% {
            transform: rotate(180deg);
        }
        to {
            transform: rotate(360deg);
        }
    }

    /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
    .ivu-spin-fix {
        position: fixed;
    }

    .multiselect__input, .multiselect__single {
        font-size: 0.9em;
    }

    .multiselect, .multiselect__input, .multiselect__single {
        font-size: 14px;
    }

    .multiselect {
        width: auto;
        min-height: 20px;
        max-height: 30px;
        flex: 1;
        text-align: right;
    }

    .multiselect__single {
        padding-left: 5px;
        margin-bottom: 0px;
        margin-top: 3px;
        font-size: 0.9em;
    }

    .multiselect__tags {
        min-height: 20px;
        max-height: 30px;
        display: block;
        padding: 0px 40px 0 8px;
        border-radius: 5px;
        border: 1px solid #e8e8e8;
        background: #fff;
        font-size: 14px;
    }

    .multiselect__select{
        padding-top: 0px;
        height: 25px;
    }

    .multiselect--active{

    }

</style>

